module Page5.Model exposing (..)
import Json.Decode as D

type alias Model =
  {title: String
  ,items: List Item}

type alias Item =
  {name: String
  ,desc: String
  ,urls: List Url}

type alias Url =
  {title: String
  ,url: String}

decoder: D.Decoder Model
decoder = 
  D.map2 Model
    (D.field "title" D.string)
    (D.field "items" (D.list item_decoder))

item_decoder: D.Decoder Item
item_decoder = 
  D.map3 Item
    (D.field "name" D.string)
    (D.field "desc" D.string)
    (D.field "urls" (D.list url_decoder))

url_decoder: D.Decoder Url
url_decoder =
  D.map2 Url
    (D.field "title" D.string)
    (D.field "url" D.string)